// pages/API/request/request.js
const config = require('../../../config/index')
const requestUrl = config.requestUrl
const requestData ={
    noncestr: Date.now(),
    testdata:'123456'
  }
const requestHeader ={
    'content-type': 'application/json',
    'test1':'abcd',
    'test2':'decskd'
}
const duration = 2000

Page({
  makeRequest() {
    const self = this

    self.setData({
      loading: true
    })

    mp.request({
      url: requestUrl,
      data: requestData,
      header: requestHeader,
      success(result) {
        mp.showToast({
          title: '请求成功，控制台查看返回数据',
          icon: 'success',
          mask: true,
          duration,
        })
        self.setData({
          loading: false
        })
        console.log('request success：抓包查看接口请求接口与控制台数据对比请求header', requestHeader)
        console.log('request success：抓包查看接口请求接口与控制台数据对比请求data', requestData)
        console.log('request success：接口返回数据', result)
      },

      fail({errMsg}) {
        console.log('request fail', errMsg)
        self.setData({
          loading: false
        })
      }
    })
  }
})
